package com.yuxinmuyu.sports_management.controller.publicController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuxinmuyu.sports_management.bean.entiy.SportsApply;
import com.yuxinmuyu.sports_management.bean.request.*;
import com.yuxinmuyu.sports_management.bean.response.SportsApplyResponse;
import com.yuxinmuyu.sports_management.bean.response.SportsProjectResponse;
import com.yuxinmuyu.sports_management.exception.R;
import com.yuxinmuyu.sports_management.service.SportsApplyService;
import com.yuxinmuyu.sports_management.utils.UserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sportApply")
@Api(value="运动项目报名",tags = {"运动会项目报名"})
public class SportsApplyController {
   @Resource
   private SportsApplyService sportsApplyService;
   @ApiOperation("获取项目申请表分页")
   @PostMapping("/getSportsApply")
   public R<Page<SportsApplyResponse>> getSportsApply(@RequestBody @Validated GetSportsApplyRequest request) {
      return R.success(sportsApplyService.getSportsApply(request));
   }
   @ApiOperation("获取项目申请表分页")
   @PostMapping("/getMySportsApply")
   public R<Page<SportsApplyResponse>> getMySportsApply(@RequestBody @Validated GetSportsApplyRequest request) {
      request.setKeyword(UserUtil.getUserId());
      return R.success(sportsApplyService.getSportsApply(request));
   }
   @ApiOperation("获取项目的下拉框")
   @PostMapping("/getSportsSelectList")
   public R<List<SportsProjectResponse>> getSelectList(@RequestBody @Validated GetSportsListRequest request){
      List<SportsProjectResponse>list=sportsApplyService.getselectList(request);
      list.add(0,new SportsProjectResponse(null,"全部"));
      return R.success(list);
   }
   @ApiOperation("插入报名信息")
   @PostMapping("/insertSportsApply")
   public R<?> insertSportsApply(@RequestBody @Validated InsertSportsApplyRequest request) {
      sportsApplyService.insertSportsApply(request);
      return R.success("添加成功！");
   }
   @ApiOperation("根据报名单ID删除信息")
   @PostMapping("/deleteSportsApply")
   public R<?> deleteSportsApply(@RequestBody @Validated GetSportsApplyinfoRequest request) {
      sportsApplyService.deleteSportsApply(request);
      return R.success("删除成功！");
   }
   @ApiOperation("用于登记成绩时获取项目申请表分页1")
   @PostMapping("/getSportsApply1")
   public R<Page<SportsApplyResponse>> getSportsApply1(@RequestBody @Validated GetSportsApplyRequest request) {
      return R.success(sportsApplyService.getSportsApply1(request));
   }
   @ApiOperation("根据报名单ID修改信息")
   @PostMapping("/updateSportsApply")
   public R<?>updateSportsApply(@RequestBody @Validated UpdateSportsApplyInfoRequest request){
      sportsApplyService.updateSportsApply(request);
      return R.success("修改成功");
   }

   @ApiOperation("管理员同意申请")
   @PostMapping("/adm/change")
   public R<?>change(@RequestBody @Validated SportsApply request) {
      sportsApplyService.change(request);
      return R.success("选中成功！");
   }
}

